package com.zhixinhuixue.zsyte.xxx.ui.activity;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.zhixinhuixue.zsyte.xxx.R;
import com.zhixinhuixue.zsyte.xxx.app.base.BaseActivity;

import com.zhixinhuixue.zsyte.xxx.app.base.BaseFragment;
import com.zhixinhuixue.zsyte.xxx.databinding.ActivityMembeBinding;
import com.zhixinhuixue.zsyte.xxx.ui.fragment.LoginFragment;
import com.zhixinhuixue.zsyte.xxx.ui.fragment.RegisterFragment;


import java.util.ArrayList;
import java.util.List;

import me.hgj.mvvmhelper.base.BaseViewModel;

public class BTLoginActivity extends BaseActivity<BaseViewModel, ActivityMembeBinding>{
 private ViewPagerAdapter viewPagerAdapter;
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        mToolbar.setCenterTitle("");
        viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        int currentItem = mDataBind.viewPager.getCurrentItem();

        mDataBind.viewPager.setAdapter(viewPagerAdapter);
        mDataBind.viewPager.setCurrentItem(1);
        mDataBind.viewPager. setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                Log.i("TAG", "initViessswq: "+position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mDataBind.tabLayout.setTabTextColors(BTLoginActivity.this.getColor(R.color.colorDivider), BTLoginActivity.this.getColor(R.color.colorWhite));
        mDataBind.tabLayout.setSelectedTabIndicatorHeight(0);
        mDataBind.tabLayout.setupWithViewPager(mDataBind.viewPager);
    }
    public class ViewPagerAdapter extends FragmentPagerAdapter {
        private List<String> titles = new ArrayList<String>();
        private List<BaseFragment> fragments = new ArrayList<>();
        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);

            titles.add("注册");
            titles.add("登录");
            fragments.add(new RegisterFragment());
            fragments.add(new LoginFragment());
        }

        @Override
        public Fragment getItem(int position) {
            Log.i("TAG", "initViewb: "+position);
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return titles.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            Log.i("TAG", "initViewb: "+position);
            return titles.get(position);
        }
    }
}
